package com.office.supplies.controller;

import com.github.pagehelper.PageInfo;
import com.office.supplies.pojo.Buy;
import com.office.supplies.pojo.Result;
import com.office.supplies.pojo.dto.SelectBuyListDTO;
import com.office.supplies.pojo.vo.BuyListVO;
import com.office.supplies.service.BuyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author admin
 * @Description 采购/进货相关接口
 * @Date 2023/12/11/0:54
 */
@RestController
@Slf4j
@RequestMapping("/buy")
public class BuyController {

    @Autowired
    private BuyService buyService;

    /**
     * 采购商品
     *
     * @param buy Buy
     * @return Result<String>
     */
    @PostMapping("/buy_goods")
    public Result<String> buyGoods(@RequestBody Buy buy){
        log.info("采购商品:{}", buy);
        buyService.butGoods(buy);
        return Result.success("采购成功！");
    }
    // 通过入库审核
    @GetMapping("/pass/{id}")
    public Result<String> pass(@PathVariable("id") Long id){
        log.info("通过入库审核:{}",id);
        buyService.pass(id);
        return Result.success("通过入库审核成功！");
    }

    /**
     * 删除采购信息
     *
     * @param buy Buy
     * @return Result<String>
     */
    @PostMapping("/delete")
    public Result<String> deleteBuyInfo(@RequestBody Buy buy){
        log.info("删除采购信息:{}",buy);
        buyService.deleteBuyInfo(buy);
        return Result.success();
    }

    /**
     * 查询采购订单
     *
     * @param pageNum Integer
     * @param pageSize Integer
     * @param selectBuyListDTO SelectBuyListDTO
     * @return Result<PageInfo<Goods>>
     */
    @PostMapping("/list/{pageNum}/{pageSize}")
    public Result<PageInfo<BuyListVO>> getGoodsList(@PathVariable("pageNum") Integer pageNum,
                                                    @PathVariable("pageSize") Integer pageSize,
                                                    @RequestBody SelectBuyListDTO selectBuyListDTO){
        log.info("查询采购订单：{}，{}，{}",pageNum,pageSize,selectBuyListDTO);
        return Result.success(buyService.getBuyListByPageAndCondtion(pageNum,pageSize,selectBuyListDTO));
    }

    /**
     * 修改采购订单
     *
     * @param buy Buy
     * @return Result<String>
     */
    @PutMapping("/update_buy_info")
    public Result<String> updateBuyInfo(@RequestBody Buy buy){
        log.info("修改采购订单:{}",buy);
        buyService.updateBuyInfo(buy);
        return Result.success("修改成功！");
    }

}
